package com.xueyi.aixihu.controller;

import com.xueyi.aixihu.controller.base.BaseController;
import com.xueyi.aixihu.exception.SzException;
import com.xueyi.aixihu.reqeust.ChangeClassifyReq;
import com.xueyi.aixihu.reqeust.NewsTypeReq;
import com.xueyi.aixihu.response.ArticleListResponse;
import com.xueyi.aixihu.response.base.BaseResponse;
import com.xueyi.aixihu.service.NewsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * leiyu
 */
@RestController
public class NewsTypeController extends BaseController {

    @Autowired
    private NewsTypeService newTypeService;

    /**
     * 条件查询文章列表顶层信息（父id=0）
     */
    @RequestMapping("/newType/list")
    public BaseResponse<List<NewsTypeReq>> getList(NewsTypeReq newsTypeReq) {
        List<NewsTypeReq> list;
        list = newTypeService.getList(newsTypeReq);
        return BaseResponse.success(list);
    }

    /**
     * 根据父id条件查询文章列表非顶层信息
     */
    @PostMapping("/newType/listById")
    public BaseResponse<List<NewsTypeReq>> getListById(NewsTypeReq newsTypeReq) throws ParseException {
        List<NewsTypeReq> list;
        list = newTypeService.getListById(newsTypeReq);
        return BaseResponse.success(list);
    }

    /**
     * 根据传入id删除非顶层信息
     */
    @PostMapping("/newType/deleteById")
    public BaseResponse<Object> deleteById(String id) throws SzException {
         newTypeService.deleteById(id);
        return new BaseResponse<>(200,"删除成功");
    }

    /**
     * 新增文章非顶层信息
     */
    @PostMapping("/newType/createType")
    public BaseResponse<Object> createType(NewsTypeReq newsTypeReq) throws SzException {
        newTypeService.createType(newsTypeReq);
        return new BaseResponse<>(200,"新增成功");
    }

    /**
     * 修改文章非顶层信息
     */
    @PostMapping("/newType/updateType")
    public BaseResponse<Object> updateType(NewsTypeReq newsTypeReq) throws SzException {
        newTypeService.updateType(newsTypeReq);
        return new BaseResponse<>(200,"修改成功");
    }
}
